using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace DataSystemWebService.DataSystemManager
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string _dataPath = "../App_Data";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            { 
                //Load Tree View
                LoadTreeView();
            }
        }

        private void LoadTreeView()
        {
            Gigaframe.DataSystem ds = new Gigaframe.DataSystem(Server.MapPath(_dataPath));

            TreeNode n = ds.GetDataSystemSchema();
            n.Text = "Databases";
            tvSchema.Nodes.Add(n);
        }

        protected void tvSchema_SelectedNodeChanged(object sender, EventArgs e)
        {
            //Get Selected Database and Table and Display Data
            DataTable dt = null;
            ArrayList selectedparams = Gigaframe.DataSystem.ParseSelectedSchemaNode(tvSchema.SelectedValue);

            Gigaframe.DataSystem ds = new Gigaframe.DataSystem(Server.MapPath(_dataPath));

            if (selectedparams.Count >= 2)
            {
                dt = ds.GetDataTable(selectedparams[0].ToString(), selectedparams[1].ToString(), "", "");

                gvData.DataSource = dt.DefaultView;
                gvData.DataBind();
            }
        }


    }
}
